package com.punai.config.controller;

import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.config.service.ConfigTemplateService;
import com.punai.config.sqlitedomain.Structure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/config/indicatorTemplateStruct")
public class ConfigTemplateStructController extends BaseController {

    @Autowired
    private ConfigTemplateService configTemplateService;

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplateStruct:list')")
    @GetMapping("/getStructList/{templateId}")
    public AjaxResult getStructList(@PathVariable String templateId) {
        return AjaxResult.success(configTemplateService.findStrutsTab(templateId));
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplateStruct:query')")
    @GetMapping("/getNewStructureCode")
    public AjaxResult getNewStructureCode() {
        return AjaxResult.success("成功",configTemplateService.getNewStructureCode());
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplateStruct:add')")
    @PostMapping
    public AjaxResult addStruct(@RequestBody Structure structure) {
        configTemplateService.saveStruts(structure);
        return AjaxResult.success("成功");
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplateStruct:update')")
    @PutMapping
    public AjaxResult updateStruct(@RequestBody Structure structure) {
        configTemplateService.saveStruts(structure);
        return AjaxResult.success("成功");
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplateStruct:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable String id) {
        Structure oneOfStructure = configTemplateService.findOneOfStructure(id);
        return AjaxResult.success(oneOfStructure);
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplateStruct:remove')")
    @DeleteMapping("/{templateId}/{id}")
    public AjaxResult deleteStruct(@PathVariable String templateId, @PathVariable String id) {
        configTemplateService.removeStruts(templateId,id);
        return AjaxResult.success("成功");
    }

    @PreAuthorize("@ss.hasPermi('config:indicatorTemplateStruct:edit')")
    @PutMapping("/updateSort/{ids}")
    public AjaxResult updateSort(@PathVariable String ids) {
        configTemplateService.updateSort(ids);
        return AjaxResult.success("成功");
    }

}
